/**
 * grayrabbit Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package com.grayrabbit.slacker.factory;

import java.util.HashMap;
import java.util.Map;

import com.grayrabbit.slacker.dababase.DatabaseProvider;

/**
 * 数据库处理对象构建工厂类
 * 
 * @author liyd
 * @version $Id: DatabaseProdiverFactory.java, v 0.1 2012-5-11 下午12:55:46 liyd Exp $
 */
public class DatabaseProdiverFactory {

    /**
     * 数据库类型
     */
    private String                     databaseName;

    /** 实例化的处理类对象 */
    private static Map<String, Object> databaseProviderClass = new HashMap<String, Object>();

    /**
     * 添加一个实例化类对象
     * 
     * @param classId
     * @param clazz
     */
    public static synchronized void addProviderClass(String classId, Object clazz) {

        if (databaseProviderClass.get(classId) == null) {
            databaseProviderClass.put(classId, clazz);
        }
    }

    /**
     * 获取一个实例化类对象
     * 
     * @param classId
     * @return
     */
    public static Object getProviderClass(String classId) {

        return databaseProviderClass.get(classId);

    }

    /**
     * 构造方法
     * @param databaseName
     */
    public DatabaseProdiverFactory(String databaseName) {

        this.databaseName = databaseName;
    }

    /**
     * 根据数据库类型构建一个数据库处理对象
     * 
     * @return
     */
    public DatabaseProvider builerDatabaseProvider() {

        return (DatabaseProvider) getProviderClass(this.databaseName);

    }

}
